*************************************************
* Setup Data Directories 
*************************************************
// Please set the working directory to the Code folder here
//cd "\To_Share\Code"

global Data "../Data"
global Output "../Output"

*************************************************
* Packages
*************************************************
* Install ftools (remove program if it existed previously)
cap ado uninstall ftools
net install ftools, from("https://raw.githubusercontent.com/sergiocorreia/ftools/master/src/") replace

* Install reghdfe
cap ado uninstall reghdfe
net install reghdfe, from("https://raw.githubusercontent.com/sergiocorreia/reghdfe/master/src/") replace

* Install ivreg2, the core package
cap ado uninstall ivreg2
ssc install ivreg2

* Finally, install this package
cap ado uninstall ivreghdfe
net install ivreghdfe, from("https://raw.githubusercontent.com/sergiocorreia/ivreghdfe/master/src/") replace

* Package for Figures
ssc install bgshade, replace

*************************************************
* Input the Data
*************************************************
// Input the Person level Data
import excel using "$Data/Base_Data.xlsx", first sheet("Person") clear
// Now we create two version of the data - the base file and one for robustness
// One with no filters on Minimum Differential Distance
save "$Data/Temp_Files/Person_Robustness", replace
// Filter out observations between -20 to 20 Miles
keep if diff_dist_min > -20 & diff_dist_min < 20
save "$Data/Temp_Files/Person_Base", replace

// Input Facility Level Data
import excel using "$Data/Base_Data.xlsx", first sheet("Facility") clear
save "$Data/Temp_Files/Facility_Base", replace

// Input Aggregate Data
import excel using "$Data/Base_Data.xlsx", first sheet("Aggregate") clear
save "$Data/Temp_Files/Aggregate_Base", replace

*************************************************
* Run the Do Files
*************************************************
// File to generate all tables
do Tables.do
// File to generate all figures
do Figures.do